$.namespace("common.textEditor");

common.textEditor.commonOpts=null;
common.textEditor.editorPop=null;
common.textEditor.mainContent=null;
common.textEditor.editorFlag=false;
common.textEditor.allHrefPath={};
common.textEditor.autoNumber=0;
common.textEditor.init=function (opts){
	common.textEditor.editorFlag=false;
	var tmpl = heredoc(function(){/*
	    
		<table style="width:100%;height:100%;border:0px;border-spacing:0px;background-color:#e3e3e3;">
			<tr>
			<td>
			<iframe class="mainFrame" style="width:100%;height:100%;background-color:#fff;" >
				
			</iframe>
			</td>
			<td width="120">
			<div style="height:100%;margin-left:20px;padding:10px;">
				<input type="button" class="toolBtn titleBtn"  onclick="common.textEditor.editorTitle('')"/>
				<input type="button" class="toolBtn contentBtn"  onclick="common.textEditor.editorContent('')"/>
				<input type="button" class="toolBtn picBtn"  onclick="common.textEditor.editorPic('')"/>
				<input type="button" class="toolBtn musicBtn"  onclick="common.textEditor.editorMusic('')"/>
				<input type="button" class="toolBtn videoBtn"  onclick="common.textEditor.editorVideo('')"/>
				<input type="button" class="toolBtn hrefBtn"  onclick="common.textEditor.editorHref()"/>
				<input type="button" class="toolBtn eidtorBtn" style="display:none;" value="修改"  onclick="common.textEditor.editorElement()"/>
				<input type="button" class="toolBtn deleteBtn" style="display:none;" value="删除" onclick="common.textEditor.deleteElement()"/>
			</div>
			</td>
			</tr>
			
			<tr height="40px">
			<td colspan="2" style="text-align:center;">
			<div class="textEditorPopWin"></div>
			
			<input type="hidden" class="autoNumber" />
			<input type="button" value="保存"  class="saveBtn" onclick="common.textEditor.saveEditor()"/>
			<input type="button" value="关闭"  class="saveBtn" onclick="common.textEditor.closeEditor()"/>
			</td>
			</tr>
		</table>
	 */});
	var item = $("<div></div>").html(tmpl).appendTo("body");
	opts.self = item;
	common.textEditor.commonOpts=opts;
	common.textEditor.editorPop = common.textEditor.commonOpts.self.find(".textEditorPopWin");
	/*common.textEditor.mainContent=opts.self.find(".mainFrame").contents().find("body");*/
	//item.find(".mainFrame").contents().find("body").append(common.textEditor.mainContent);
	
	liandisys.dialog.showWindowByItem({
        item: item,
        resizable: false,
        title: opts.title || "文本编辑",
        width: opts.width || 460,
        height: opts.height || 550
    });
	
var tmplT = heredoc(function(){/*
<style>
	    .chooseElement{
			border:1px solid #ccc;
	
		}
		.musicDiv{
			text-align:center;
			background-color:#ccc;
			width:100%;
			height:30px;
		}
</style>
	 */});
	common.textEditor.commonOpts.self.find(".mainFrame").contents().find("head").append(tmplT);
	
	if(common.textEditor.commonOpts.textContent!=null&&common.textEditor.commonOpts.textContent!=""){
		common.textEditor.commonOpts.self.find(".mainFrame").contents().find("body").append(common.textEditor.commonOpts.textContent);
		//common.textEditor.commonOpts.self.find(".mainFrame").contents().find("body").find(".autoNumber").val();
	}else{
		var resourceDiv=$("<div class='resourceDiv' style='display:none;'></div>");
		var inCodeDiv=$("<div class='inCodeDiv' style='display:none;'></div>");
		common.textEditor.commonOpts.self.find(".mainFrame").contents().find("body").append(resourceDiv);
		common.textEditor.commonOpts.self.find(".mainFrame").contents().find("body").append(inCodeDiv);
		var autoNumber=$("<input type='hidden' class='autoNumber' />");
		common.textEditor.commonOpts.self.find(".mainFrame").contents().find("body").append(autoNumber);
		
	}
};


var HtmlUtil = {
	    /*1.用浏览器内部转换器实现html转码*/
	    htmlEncode:function (html){
	        //1.首先动态创建一个容器标签元素，如DIV
	        var temp = document.createElement ("div");
	        //2.然后将要转换的字符串设置为这个元素的innerText(ie支持)或者textContent(火狐，google支持)
	        (temp.textContent != undefined ) ? (temp.textContent = html) : (temp.innerText = html);
	        //3.最后返回这个元素的innerHTML，即得到经过HTML编码转换的字符串了
	        var output = temp.innerHTML;
	        temp = null;
	        return output;
	    },
	    /*2.用浏览器内部转换器实现html解码*/
	    htmlDecode:function (text){
	        //1.首先动态创建一个容器标签元素，如DIV
	        var temp = document.createElement("div");
	        //2.然后将要转换的字符串设置为这个元素的innerHTML(ie，火狐，google都支持)
	        temp.innerHTML = text;
	        //3.最后返回这个元素的innerText(ie支持)或者textContent(火狐，google支持)，即得到经过HTML解码的字符串了。
	        var output = temp.innerText || temp.textContent;
	        temp = null;
	        return output;
	    }
	};


common.textEditor.addClickEvent=function(){
	
	common.textEditor.commonOpts.self.find(".mainFrame").contents().find("body").children().click(
			function() {
				console.log($(this));
				common.textEditor.commonOpts.self.find(".mainFrame").contents().find("body").find(".chooseElement").removeClass("chooseElement");
				if($(this).is("a")){
					$(this).children().addClass("chooseElement");
					common.textEditor.commonOpts.self.find(".eidtorBtn").show();
					common.textEditor.commonOpts.self.find(".deleteBtn").show();
				}else{
					$(this).addClass("chooseElement");
					common.textEditor.commonOpts.self.find(".eidtorBtn").show();
					common.textEditor.commonOpts.self.find(".deleteBtn").show();
				}
				
			});
};



function heredoc(fn) {
    return fn.toString().split('\n').slice(1,-1).join('\n') + '\n';
}

common.textEditor.editorTitle=function(value){
	var tmpl = heredoc(function(){/*
		<table style="width:100%;height:100%;border:0px;border-spacing:0px;">
			<tr>
			<td>
			<div style="width:100%;height:100%;">
				<textarea rows="5" class="editorText" style="width:98%;"></textarea>
			</div>
			</td>
			</tr>
			<tr>
				<td>
				<input type="button"  value="保存" class="saveBtn" onclick="common.textEditor.saveTitle()"/>
				<input type="button"  value="关闭" class="saveBtn" onclick="common.textEditor.close()"/>
				</td>
			</tr>
		</table>
	 */});
	var item = common.textEditor.editorPop.html(tmpl);
	liandisys.dialog.showWindowByItem({
        item: item,
        resizable: false,
        title:"标题",
        width: 300,
        height: 200
    });
	common.textEditor.editorPop.find(".editorText").val(value);
};


common.textEditor.saveTitle=function(){
	var texts=common.textEditor.editorPop.find(".editorText");
	var text=texts.val();
	text=HtmlUtil.htmlEncode(text);
	text=text.replace(/ /g,"&nbsp;");
	text=text.replace(/\n/g,"<br/>");
	var title=$("<h1 align='center'>"+text+"</h1>");
	//debugger;
	if(common.textEditor.editorFlag==false){
		common.textEditor.commonOpts.self.find(".mainFrame").contents().find("body").append(title);
	}else{
		common.textEditor.commonOpts.self.find(".mainFrame").contents().find("body").find(".chooseElement").html(text);
	}
	
	common.textEditor.addClickEvent();
	common.textEditor.editorFlag=false;
	common.textEditor.close();
};


common.textEditor.close=function(){
	common.textEditor.editorPop.panel("close");
};

common.textEditor.editorContent=function(value){
	var tmpl = heredoc(function(){/*
		<table style="width:100%;height:100%;border:0px;border-spacing:0px;">
			<tr>
			<td>
			<div style="width:100%;height:100%;">
				<textarea rows="15" class="editorText" style="width:98%;"></textarea>
			</div>
			</td>
			</tr>
			<tr>
				<td>
				<input type="button"  value="保存" class="saveBtn" onclick="common.textEditor.saveContent()"/>
				<input type="button"  value="关闭" class="saveBtn" onclick="common.textEditor.close()"/>
				</td>
			</tr>
		</table>
	 */});
	var item = common.textEditor.editorPop.html(tmpl);
	liandisys.dialog.showWindowByItem({
        item: item,
        resizable: false,
        title:"文本",
        width: 300,
        height: 400
    });
	common.textEditor.editorPop.find(".editorText").val(value);
};


common.textEditor.saveContent=function(){
	var texts=common.textEditor.editorPop.find(".editorText");
	var text=texts.val();
	text=HtmlUtil.htmlEncode(text);
	text=text.replace(/ /g,"&nbsp;");
	text=text.replace(/\n/g,"<br/>");
	/*text=text.replace(/>/g,"&gt;");
	text=text.replace(/</g,"&lt;");*/
	
	var title=$("<p>"+text+"</p>");
	//debugger;
	
	if(common.textEditor.editorFlag==false){
		common.textEditor.commonOpts.self.find(".mainFrame").contents().find("body").append(title);
	}else{
		common.textEditor.commonOpts.self.find(".mainFrame").contents().find("body").find(".chooseElement").html(text);
	}
	common.textEditor.addClickEvent();
	common.textEditor.editorFlag=false;
	common.textEditor.close();
};



common.textEditor.editorPic=function(value){
	var tmpl = heredoc(function(){/*
	<form method="post">
		<table style="width:100%;height:100%;border:0px;border-spacing:0px;">
			<tr>
			<td>
			<div style="width:100%;height:100%;">
				<input type="file" value="上传图片" name="picName"/>
				<input type="button"  value="上传" class="saveBtn" onclick="common.textEditor.uploadPic()"/>
			</div>
			</td>
			</tr>
			<tr>
			<td>
				图片路径：<input type="text" class="picPath pathInput" />
			</td>
			</tr>
			<tr>
				<td>
				
				<input type="button"  value="保存" class="saveBtn" onclick="common.textEditor.savePic()"/>
				<input type="button"  value="关闭" class="saveBtn" onclick="common.textEditor.close()"/>
				</td>
			</tr>
		</table>
	<form>
	 */});
	var item = common.textEditor.editorPop.html(tmpl);
	liandisys.dialog.showWindowByItem({
        item: item,
        resizable: false,
        title:"图片上传",
        width: 300,
        height: 300
    });
	common.textEditor.editorPop.find("form").find(".picPath").val(value);
};

common.textEditor.uploadPic=function(){
	
	common.textEditor.editorPop.find("form").ajaxSubmit({
        url: $.ctx + common.textEditor.commonOpts.uploadPath,
        type: 'post',
        beforeSubmit: function(params) {
        	params.push({name:"TYPE", value:"Image"});
        },
        success: function (data) {
        	if(data.success){
        		common.textEditor.editorPop.find("form").find(".picPath").val(data.url);
        		
        	}else{
        		console.log(data.msg);
        	}
            
        }
    });
};


common.textEditor.savePic=function(){
	var path=common.textEditor.editorPop.find("form").find(".picPath").val();
	var title=$("<img class='__resource__image__"+common.textEditor.autoNumber+"_loc' src='"+path+"' style='width:100%;height:auto;'/>");
	//debugger;
	if(common.textEditor.editorFlag==false){
		common.textEditor.commonOpts.self.find(".mainFrame").contents().find("body").append(title);
	}else{
		common.textEditor.commonOpts.self.find(".mainFrame").contents().find("body").find(".chooseElement").attr("src",path);
	}
	common.textEditor.addClickEvent();
	common.textEditor.editorFlag=false;
	var hiddenMsg=$("<input type='hidden' value='"+path+"' class='__resource__image__"+common.textEditor.autoNumber+"__src'>");
	common.textEditor.commonOpts.self.find(".mainFrame").contents().find("body").find(".resourceDiv").append(hiddenMsg);
	common.textEditor.autoNumber++;
	common.textEditor.close();
};


common.textEditor.editorMusic=function(value){
	var tmpl = heredoc(function(){/*
	<form method="post">
		<table style="width:100%;height:100%;border:0px;border-spacing:0px;">
			<tr>
			<td>
			<div style="width:100%;height:100%;">
				<input type="file" value="上传音频" name="musicName"/>
				<input type="button"  value="上传" class="saveBtn" onclick="common.textEditor.uploadMusic()"/>
			</div>
			</td>
			</tr>
			<tr>
			<td>
			音频路径：<input type="text" class="musicPath pathInput" />
			</td>
			</tr>
			<tr>
				<td>
				
				<input type="button"  value="保存" class="saveBtn" onclick="common.textEditor.saveMusic()"/>
				<input type="button"  value="关闭" class="saveBtn" onclick="common.textEditor.close()"/>
				</td>
			</tr>
			<tr>
				<td class="showAudio">
				
				</td>
			</tr>
		</table>
	<form>
	 */});
	var item = common.textEditor.editorPop.html(tmpl);
	liandisys.dialog.showWindowByItem({
        item: item,
        resizable: false,
        title:"音频上传",
        width: 300,
        height: 300
    });
	common.textEditor.editorPop.find("form").find(".musicPath").val(value);
	if(value!=""){
		common.textEditor.editorPop.find("form").find(".showAudio").html("<audio src='"+value+"' controls='controls' style='width:280px'></audio>");
	}
	
};

common.textEditor.uploadMusic=function(){
	common.textEditor.editorPop.find("form").ajaxSubmit({
        url: $.ctx + common.textEditor.commonOpts.uploadPath,
        type: 'post',
        beforeSubmit: function(params) {
        	params.push({name:"TYPE", value:"Audio"});
        },
        success: function (data) {
        	if(data.success){
        		common.textEditor.editorPop.find("form").find(".musicPath").val(data.url);
        		common.textEditor.editorPop.find("form").find(".showAudio").html("<audio src='"+data.url+"' controls='controls' style='width:280px'></audio>");
        	}else{
        		console.log(data.msg);
        	}
            
        }
    });
};


common.textEditor.saveMusic=function(){
	var path=common.textEditor.editorPop.find("form").find(".musicPath").val();
	var title=$("<div class='musicDiv'><canvas width='100%' height='30'></canvas>" +
			"<audio class='__resource__audio__"+common.textEditor.autoNumber+"__loc' src='"+path+"' controls='controls' style='display:none;'></audio>" +
			"<div>");
	//var title=$("<div><audio src='"+path+"' controls='controls'></audio><div>").width("100%").height(40);
	//debugger;
	
	if(common.textEditor.editorFlag==false){
		common.textEditor.commonOpts.self.find(".mainFrame").contents().find("body").append(title);
	}else{
		common.textEditor.commonOpts.self.find(".mainFrame").contents().find("body").find(".chooseElement").children().get(0).src=path;
	}
	var hiddenMsg=$("<input type='hidden' value='"+path+"'>");
	common.textEditor.commonOpts.self.find(".hiddenDiv").append(hiddenMsg);
	common.textEditor.addClickEvent();
	common.textEditor.editorFlag=false;
	var hiddenMsg=$("<input type='hidden' value='"+path+"' class='__resource__audio__"+common.textEditor.autoNumber+"__src'>");
	common.textEditor.commonOpts.self.find(".mainFrame").contents().find("body").find(".resourceDiv").append(hiddenMsg);
	common.textEditor.autoNumber++;
	common.textEditor.close();
};


common.textEditor.editorVideo=function(value){
	var tmpl = heredoc(function(){/*
	<form method="post">
		<table style="width:100%;height:100%;border:0px;border-spacing:0px;">
			<tr>
			<td>
			
				<input type="file" value="上传视频" name="videoName"/>
				<input type="button"  value="上传" class="saveBtn" onclick="common.textEditor.uploadVideo()"/>
			
			</td>
			</tr>
			<tr>
			<td>
				视频路径：<input type="text" class="videoPath pathInput" />
			</td>
			</tr>
			<tr>
				<td>
				
				<input type="button"  value="保存" class="saveBtn" onclick="common.textEditor.saveVideo()"/>
				<input type="button"  value="关闭" class="saveBtn" onclick="common.textEditor.close()"/>
				</td>
			</tr>
		</table>
	<form>
	 */});
	var item = common.textEditor.editorPop.html(tmpl);
	liandisys.dialog.showWindowByItem({
        item: item,
        resizable: false,
        title:"视频上传",
        width: 300,
        height: 300
    });
	common.textEditor.editorPop.find("form").find(".videoPath").val(value);
};

common.textEditor.uploadVideo=function(){
	common.textEditor.editorPop.find("form").ajaxSubmit({
        url: $.ctx + common.textEditor.commonOpts.uploadPath,
        type: 'post',
        beforeSubmit: function(params) {
        	params.push({name:"TYPE", value:"Video"});
        },
        success: function (data) {
        	if(data.success){
        		common.textEditor.editorPop.find("form").find(".videoPath").val(data.url);
        		
        	}else{
        		console.log(data.msg);
        	}
            
        }
    });
};


common.textEditor.saveVideo=function(){
	var path=common.textEditor.editorPop.find("form").find(".videoPath").val();
	var title=$("<video src='"+path+"' class='__resource__video__"+common.textEditor.autoNumber+"__loc' controls='controls'></video>");
	//debugger;
	
	if(common.textEditor.editorFlag==false){
		common.textEditor.commonOpts.self.find(".mainFrame").contents().find("body").append(title);
	}else{
		common.textEditor.commonOpts.self.find(".mainFrame").contents().find("body").find(".chooseElement").attr("src",path);
	}
	var hiddenMsg=$("<input type='hidden' value='"+path+"'>");
	common.textEditor.commonOpts.self.find(".hiddenDiv").append(hiddenMsg);
	common.textEditor.addClickEvent();
	common.textEditor.editorFlag=false;
	var hiddenMsg=$("<input type='hidden' value='"+path+"' class='__resource__video__"+common.textEditor.autoNumber+"__src'>");
	common.textEditor.commonOpts.self.find(".mainFrame").contents().find("body").find(".resourceDiv").append(hiddenMsg);
	common.textEditor.autoNumber++;
	common.textEditor.close();
};




common.textEditor.editorHref=function(){
	if(common.textEditor.commonOpts.self.find(".mainFrame").contents().find("body").find(".chooseElement").length<0){
		alert("请选择一个元素");
		return false;
	}
	
	if(common.textEditor.commonOpts.self.find(".mainFrame").contents().find("body").find(".chooseElement").is("div")){
		alert("音频元素不能加链接");
		return false;
	}
	
	if(common.textEditor.commonOpts.self.find(".mainFrame").contents().find("body").find(".chooseElement").is("video")){
		alert("视频元素不能加链接");
		return false;
	}
	var tmpl = heredoc(function(){/*
			<form method="post">
				<table style="width:100%;height:100%;border:0px;border-spacing:0px;">
					<tr>
					<td>
						链接路径：<input type="text" class="hrefPath pathInput" oninput="common.textEditor.OnInput (event)" onpropertychange="common.textEditor.OnPropChanged (event)"/>
					</td>
					</tr>
					<tr>
						<td>
						<input type="button"  value="码内跳转" class="saveBtn incode" onclick="common.textEditor.inCodeHref()"/>
						<input type="button"  value="码外跳转" class="saveBtn outCode" onclick="common.textEditor.outCodeHref()"/>
						<input type="button"  value="保存" class="saveBtn" onclick="common.textEditor.saveHref()"/>
						<input type="button"  value="关闭" class="saveBtn" onclick="common.textEditor.close()"/>
						</td>
					</tr>
				</table>
			<form>
			 */});
	
		
		var item = common.textEditor.editorPop.html(tmpl);
		liandisys.dialog.showWindowByItem({
	        item: item,
	        resizable: false,
	        title:"链接",
	        width: 300,
	        height: 300
	    });
		if(common.textEditor.commonOpts.inCode==null||common.textEditor.commonOpts.inCode==""){
			common.textEditor.editorPop.find("form").find(".incode").hide();
		}else{
			common.textEditor.commonOpts.inCode(function(value) {
				common.textEditor.editorPop.find("form").find(".hrefPath").addClass("inCode");
				common.textEditor.editorPop.find("form").find(".hrefPath").val(value);
			});
		}
		if(common.textEditor.commonOpts.outCode==null||common.textEditor.commonOpts.outCode==""){
			common.textEditor.editorPop.find("form").find(".outCode").hide();

		}else{
			common.textEditor.commonOpts.outCode(function(value) {
				common.textEditor.editorPop.find("form").find(".hrefPath").addClass("outClass");
				common.textEditor.editorPop.find("form").find(".hrefPath").val(value);
			});
		}
		if(common.textEditor.commonOpts.self.find(".mainFrame").contents().find("body").find(".chooseElement").parent().is("a")){
			var value=common.textEditor.allHrefPath[common.textEditor.commonOpts.self.find(".mainFrame").contents().find("body").find(".chooseElement")];
			common.textEditor.editorPop.find("form").find(".hrefPath").val(value);
		}
		
};

//Firefox, Google Chrome, Opera, Safari, Internet Explorer from version 9
common.textEditor.OnInput=function(event){
	
	common.textEditor.editorPop.find("form").find(".hrefPath").removeClass("inCode");
	common.textEditor.editorPop.find("form").find(".hrefPath").removeClass("outCode");
};

//Internet Explorer
common.textEditor.OnPropChanged=function(event){
	if (event.propertyName.toLowerCase () == "value") {
        acommon.textEditor.editorPop.find("form").find(".hrefPath").removeClass("inCode");
    	common.textEditor.editorPop.find("form").find(".hrefPath").removeClass("outCode");
    }
};


common.textEditor.inCodeHref=function(){
	common.textEditor.commonOpts.inCode(function(value) {
		common.textEditor.editorPop.find("form").find(".hrefPath").val(value);
		common.textEditor.editorPop.find("form").find(".hrefPath").addClass("inCode");
	});
};


common.textEditor.outCodeHref=function(){
	common.textEditor.commonOpts.outCode(function(value) {
		common.textEditor.editorPop.find("form").find(".hrefPath").val(value);
		common.textEditor.editorPop.find("form").find(".hrefPath").addClass("outCode");
	});
};

common.textEditor.saveHref=function(){
	var path=common.textEditor.editorPop.find("form").find(".hrefPath").val();
	common.textEditor.commonOpts.self.find(".mainFrame").contents().find("body").find(".chooseElement").unwrap();
	delete common.textEditor.allHrefPath[common.textEditor.commonOpts.self.find(".mainFrame").contents().find("body").find(".chooseElement")];
	common.textEditor.commonOpts.self.find(".mainFrame").contents().find("body").find(".chooseElement").wrap("<a href='javaScript:void(0);' ></a>");
	
	common.textEditor.allHrefPath[common.textEditor.commonOpts.self.find(".mainFrame").contents().find("body").find(".chooseElement")]=path;
	common.textEditor.addClickEvent();
	if(common.textEditor.editorPop.find("form").find(".hrefPath").className=="inCode"){
		var hiddenMsg=$("<input type='hidden' value='"+path+"' class='__resource__inCode__"+common.textEditor.autoNumber+"__src'>");
		common.textEditor.commonOpts.self.find(".mainFrame").contents().find("body").find(".inCodeDiv").append(hiddenMsg);
		common.textEditor.autoNumber++;
	}
	common.textEditor.close();
	
	
};


common.textEditor.deleteElement=function(){
	common.textEditor.commonOpts.self.find(".mainFrame").contents().find("body").find(".chooseElement").remove();
};

common.textEditor.editorElement=function(){
	common.textEditor.editorFlag=true;
	if(common.textEditor.commonOpts.self.find(".mainFrame").contents().find("body").find(".chooseElement").is("h1")){
		var value=common.textEditor.commonOpts.self.find(".mainFrame").contents().find("body").find(".chooseElement").html();
		common.textEditor.editorTitle(value);
	}else if(common.textEditor.commonOpts.self.find(".mainFrame").contents().find("body").find(".chooseElement").is("p")){
		var value=common.textEditor.commonOpts.self.find(".mainFrame").contents().find("body").find(".chooseElement").html();
		common.textEditor.editorContent(value);
	}else if(common.textEditor.commonOpts.self.find(".mainFrame").contents().find("body").find(".chooseElement").is("img")){
		var value=common.textEditor.commonOpts.self.find(".mainFrame").contents().find("body").find(".chooseElement").attr("src");
		common.textEditor.editorPic(value);
	}else if(common.textEditor.commonOpts.self.find(".mainFrame").contents().find("body").find(".chooseElement").is("div")){
		var value=common.textEditor.commonOpts.self.find(".mainFrame").contents().find("body").find(".chooseElement").children().get(0).src;
		//var value=common.textEditor.commonOpts.self.find(".mainFrame").contents().find("body").find(".chooseElement").attr("src");
		common.textEditor.editorMusic(value);
	}else if(common.textEditor.commonOpts.self.find(".mainFrame").contents().find("body").find(".chooseElement").is("video")){
		var value=common.textEditor.commonOpts.self.find(".mainFrame").contents().find("body").find(".chooseElement").attr("src");
		common.textEditor.editorVideo(value);
	}
};

common.textEditor.saveEditor=function(){
	common.textEditor.commonOpts.backFn(common.textEditor.commonOpts.self.find(".mainFrame").contents().find("body").html());
};

common.textEditor.closeEditor=function(){
	common.textEditor.commonOpts.self.panel("close");
};